package com.norteksoft.erm.model;

import java.sql.Timestamp;
import java.util.Date;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * @hibernate.class table="ERM_FUNCPERMISSION"
 * @author Jiffy
 * 
 */
public class FuncPermission extends BaseObject {

	// 授予对象类型
	public static final String AUTHORITY_TYPE_GROUP = "GROUP";// 授予部门

	public static final String AUTHORITY_TYPE_ROLE = "ROLE";// 授予角色

	public static final String AUTHORITY_TYPE_USER = "USER";// 授予用户

	// 授权方式
	public static final String GRANT_TYPE_MANAGE = "mange";// 一级授权（系统管理员在ERM中做的授权）

	public static final String GRANT_TYPE_DELEGATE = "delegate";// 二级授权（普通用户做的授权）

	private Long OID = new Long(-1);

	private Resource resource;// 功能资源

	private String authorityCode;// 功能授予对象（冗余）

	private String authorityType;// 功能授予对象类型

	private String authorityName;// 功能授予对象名称（冗余）

	private Long authorityOID;// 功能授予对象OID（冗余）

	private Date expireDate;// 授权失效时间

	private String starred;// 已加星标？true/false

	// =================== 委托属性 ===================
	private String grantable;// 是否允许委托，空/mange/delegate

	private String grantScope;// 委托范围，为空表示不限，值可以是GROUP_groupcode/ROLE_rolecode

	// =================== 日志属性 ===================
	private String createBy;// 谁做的授权？

	private Timestamp authzTime;// 授权时间

	private String remark;// 备注

	private String lastModifyBy;// 谁最后做过修改？

	public int hashCode() {
		return new HashCodeBuilder().append(OID).append(authorityCode).append(
				authorityType).append(authorityName).append(authorityOID)
				.append(expireDate).append(starred).append(grantable).append(
						grantScope).append(createBy).append(authzTime).append(
						remark).append(lastModifyBy).toHashCode();
	}

	/**
	 * @hibernate.id column="OID" unsaved-value="-1" type="long"
	 * @hibernate.generator class="sequence"
	 * @hibernate.param name="sequence" value="ERM_SEQUENCE"
	 */

	public Long getOID() {
		return OID;
	}

	public void setOID(Long oid) {
		OID = oid;
	}

	/**
	 * @hibernate.property column="AUTHORITYCODE" length="60" type="string"
	 *                     not-null="true"
	 * @return String
	 */
	public String getAuthorityCode() {
		return authorityCode;
	}

	public void setAuthorityCode(String authority) {
		this.authorityCode = authority;
	}

	/**
	 * @hibernate.property column="AUTHORITYNAME" length="60" type="string"
	 *                     not-null="true"
	 * @return String
	 */
	public String getAuthorityName() {
		return authorityName;
	}

	public void setAuthorityName(String authorityName) {
		this.authorityName = authorityName;
	}

	/**
	 * @hibernate.property column="AUTHORITYTYPE" length="30" type="string"
	 *                     not-null="true"
	 * @return String
	 */
	public String getAuthorityType() {
		return authorityType;
	}

	public void setAuthorityType(String authorityType) {
		this.authorityType = authorityType;
	}

	/**
	 * @hibernate.many-to-one name="resource" column="RSID"
	 *                        class="com.norteksoft.erm.model.Resource"
	 */
	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

	/**
	 * @hibernate.property column="AUTHORITYOID" type="long"
	 */

	public Long getAuthorityOID() {
		return authorityOID;
	}

	public void setAuthorityOID(Long authorityOID) {
		this.authorityOID = authorityOID;
	}

	/**
	 * @hibernate.property column="EXPIREDATE" type="java.util.Date"
	 */

	public Date getExpireDate() {
		return expireDate;
	}

	public void setExpireDate(Date expireDate) {
		this.expireDate = expireDate;
	}

	public String getAuthority() {
		return authorityType + "_" + authorityCode;
	}

	/**
	 * @hibernate.property column="GRANTABLE" length="5" type="string"
	 * @return String
	 */
	public String getGrantable() {
		return grantable;
	}

	public void setGrantable(String grantable) {
		this.grantable = grantable;
	}

	/**
	 * @hibernate.property column="STARRED" length="5" type="string"
	 * @return String
	 */

	public String getStarred() {
		return starred;
	}

	public void setStarred(String starred) {
		this.starred = starred;
	}

	public String getGrantScope() {
		return grantScope;
	}

	public void setGrantScope(String grantScope) {
		this.grantScope = grantScope;
	}

	/**
	 * @hibernate.property column="CREATEBY" length="30" type="string"
	 * @return String
	 */

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	/**
	 * @hibernate.property column="LASTMODIFYBY" length="30" type="string"
	 * @return String
	 */

	public String getLastModifyBy() {
		return lastModifyBy;
	}

	public void setLastModifyBy(String lastModifyBy) {
		this.lastModifyBy = lastModifyBy;
	}

	/**
	 * @hibernate.property column="AUTHZTIME" type="timestamp"
	 * @return Timestamp
	 */
	public Timestamp getAuthzTime() {
		return authzTime;
	}

	public void setAuthzTime(Timestamp authzTime) {
		this.authzTime = authzTime;
	}

	/**
	 * @hibernate.property column="REMARK" length="300" type="string"
	 * @return String
	 */
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
